home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1996, 1997 Meta Four Software. All rights reserved.
- //
- // This file contains the declaration of standard strings / collections.
- //
- //! rev="$Id: m4wrap.h,v 1.8 1997/06/06 15:20:30 jcw Rel $"
-
- #ifndef __M4WRAP_H__
- #define __M4WRAP_H__
-
- #include <string>
- #include <vector>
-
- #if !defined (d4_std) // the default is to use namespaces
- #define d4_std std
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // Declarations in this file
-
- class c4_String;
-
- // class c4_ArrayT;
- // class c4_PtrArray;
-
- /////////////////////////////////////////////////////////////////////////////
-
- class c4_String : public d4_std::string
- {
- typedef d4_std::string string;
-
- public:
- c4_String ();
- c4_String (char ch, int nDup =1);
- c4_String (const char* str);
- c4_String (const void* ptr, int len);
- c4_String (const d4_std::string& s);
- c4_String (const c4_String& s);
- ~c4_String ();
-
- const c4_String& operator= (const c4_String&);
-
- operator const char* () const;
-
- char operator[] (int i) const;
-
- friend c4_String operator+ (const c4_String&, const c4_String&);
- friend c4_String operator+ (const c4_String&, const char*);
- friend c4_String operator+ (const char*, const c4_String&);
-
- const c4_String& operator+= (const c4_String& s);
- const c4_String& operator+= (const char* s);
-
- int GetLength() const;
- bool IsEmpty() const;
- void Empty();
-
- c4_String Mid(int nFirst, int nCount =25000) const;
- c4_String Left(int nCount) const;
- c4_String Right(int nCount) const;
-
- int Compare(const char* str) const;
- int CompareNoCase(const char* str) const;
-
- bool operator< (const c4_String& str) const;
-
- int Find(char ch) const;
- int ReverseFind(char ch) const;
- int FindOneOf(const char* set) const;
-
- int Find(const char* sub) const;
-
- c4_String SpanIncluding(const char* set) const;
- c4_String SpanExcluding(const char* set) const;
- };
-
- bool operator== (const c4_String&, const c4_String&);
- bool operator!= (const c4_String&, const c4_String&);
-
- bool operator== (const c4_String& s1, const char* s2);
- bool operator== (const char* s1, const c4_String& s2);
-
- bool operator!= (const c4_String& s1, const char* s2);
- bool operator!= (const char* s1, const c4_String& s2);
-
- /////////////////////////////////////////////////////////////////////////////
-
- template<class T>
- class c4_ArrayT
- {
- d4_std::vector< T, d4_std::allocator<T> > _base;
-
- public:
- c4_ArrayT () { }
- ~c4_ArrayT () { }
-
- int GetSize() const { return _base.size(); }
- void SetSize(int nNewSize, int =-1) { _base.resize(nNewSize); }
-
- T GetAt(int nIndex) const { return _base[nIndex]; }
- T& ElementAt(int nIndex) { return _base[nIndex]; }
-
- void SetAt(int nIndex, const T& newElement)
- {
- _base[nIndex] = newElement;
- }
-
- int Add(const T& newElement)
- {
- int n = _base.size();
- _base.push_back(newElement);
- return n;
- }
-
- void InsertAt(int nIndex, const T& newElement, int nCount =1)
- {
- _base.insert(&_base[nIndex], nCount, newElement);
- }
-
- void RemoveAt(int nIndex, int nCount =1)
- {
- _base.erase(&_base[nIndex], &_base[nIndex+nCount]);
- }
- };
-
- /////////////////////////////////////////////////////////////////////////////
-
- #if q4_INLINE
- #include "m4wrap.inl"
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
-
- #endif
-